<%@page import="com.bionic.banking.logic.controller.BankAccountController"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Bank Accounts List</title>            
        <script type="text/javascript" src="../resources/script/ui/jquery-ui.js"></script>        
        <script type="text/javascript" language="javascript" >                 
                    function editRecord(id)
                    {                                       
                            var f=document.forms[0];                                
                            f.method="post";                                
                            //f.action='../bankaccount/Edit.jsp?id='+id;                                
                            f.action='Controller?command=startEditBankAccount&id='+id;
                            f.submit();
                    }
                    
                    function deleteRecord(id)
                    {                          
                         var result = confirm('Are you sure to delete the bank account [' + id +'] ?')
                         if(result == 1)
                         {        
                              var f=document.forms[0];                             
                              f.method="post";
                              f.action='../bankaccount/Delete.jsp?id='+id;//TODO:
                              f.submit();                                               
                         }
                    }
        </script>        
    </head>
    <body>        
        <h3>Bank Accounts List</h3> 
        <form action="../Controller" method="post">            
           <table id="tblList" border="3">
                <tr>
                    <th bgcolor=silver>Account Id</th>
                    <th bgcolor=silver>Customer</th>
                    <th bgcolor=silver>Account Type</th>                    
                    <th bgcolor=silver>Description</th>                    
                    <th bgcolor=silver>Balance</th>                                    
                    <th bgcolor=silver>Credit</th>                    
                    <th bgcolor=silver />
                    <th bgcolor=silver />
                </tr>
            
      <jsp:useBean id="bankAccountsBean" class="com.bionic.banking.logic.controller.BankAccountController" />
      <jsp:useBean id="customerBean" class="com.bionic.banking.logic.controller.CustomerController"/>
      <jsp:useBean id="domainHelperBean" class="com.bionic.banking.logic.DomainUtil" />
      
            <c:forEach var="account" begin="0" items="${bankAccountsBean.getAll()}">                
                <tr>
                    <td>${account.accountId}&nbsp;&nbsp;</td>                    
                    <td>
                        <a href="javascript:viewCustomerRecord(${account.customerId});" >
                            ${customerBean.getDetails(account.customerId)}
                        </a>
                    </td>
                    <td>${account.accountType}&nbsp;&nbsp;</td>     
                    <td>${account.description}&nbsp;&nbsp;</td>                    
                    <td>${domainHelperBean.getCurrencyByCode(account.currencyId).getSymbol()}
                        ${account.balance}&nbsp;&nbsp;</td>
                    <td>${account.creditLine}&nbsp;&nbsp;</td>
                    <td><a href="javascript:editRecord(${account.accountId});" >
                            <strong>View</strong></a></td> 
                    <td><a href="javascript:deleteRecord(${account.accountId});" name="delete" >
                            <strong>Delete</strong></a></td>
                </tr>
            </c:forEach>
        </table>       
        <br/>
        <a href="Controller?command=startCreateBankAccount"><strong>Register a new Bank Account</strong>
        </a>
    </form>
</body>
</html>
